package com.gitee.theskyzero.framework.tx;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tx")
@Transactional
public class TxOperation {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @PostMapping
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = RuntimeException.class)
    public void testTx() {
        jdbcTemplate.execute("insert into test(id,name) values (1,'test')");
    }
}
